<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE3</title>
  </head>
  <body>
    <div id="app"></div>

    <template id="tpl">
      <div>
        <button @click="c1">点我</button>
        <button @click="c2('yesen', $event)">打招呼</button>
        <form
          @submit.prevent="submit"
          style="border: 1px solid #666; padding: 1em; margin: 1rem auto"
        >
          <input @keyup.enter="submit" placeholder="按回车提交" />
          <button type="submit">提交</button>
        </form>
      </div>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      Vue.createApp({
        template: "#tpl",
        methods: {
          c1(e) {
            window.alert(e.target.innerText);
          },
          c2(name, e) {
            window.alert(`你好，${name}. ${e.target.innerText}`);
          },
          submit() {
            window.alert("提交表单");
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
